package com.techyuan.algorithm.utils;

import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * Created by tianjuntao on 2016/11/23.
 */
public class PrintUtil {
    public static <T> void printArrPretty(List<T> arr) {
        printPretty(StringUtils.join(arr, ","), "%s");
    }

    public static <T> void printArrPretty(T[] arr) {
        printPretty(StringUtils.join(arr, ","), "%s");
    }

    public static void printArrPretty(int[] arr) {
        printArrPretty(arr, "%s");
    }

    public static <T> void printArrPretty(List<T> arr, String format) {
        printPretty(StringUtils.join(arr, ","), format);
    }

    public static <T> void printArrPretty(T[] arr, String format) {
        printPretty(StringUtils.join(arr, ","), format);
    }

    public static void printArrPretty(int[] arr, String format) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            if (i != 0)
                sb.append(",");
            sb.append(arr[i]);
        }
        printPretty(sb.toString(), format);
    }

    private static void printPretty(String str, String format) {
        System.out.println(String.format(format, str));
    }
}
